<template>
  <div class="shop">
   <el-form ref="filtrateForm" :inline="true" size="mini" :model="form" class="form">
      <el-form-item >
          <el-input class="input" v-model="form.username" placeholder="输入用户账号搜索" clearable></el-input>
        </el-form-item>
        <el-form-item >
          <el-input class="input" v-model="form.shop_name" placeholder="输入小店名称搜索" clearable></el-input>
        </el-form-item>
      <el-button size="mini" type="primary" @click="searchSaleOrder">搜索</el-button>
   </el-form>
   <el-table
      :data="tableData"
      :cell-style="tc"
      :header-cell-style="tccolor"
      v-loading="listLoading"
    >
      <el-table-column fixed prop="created_at" label="时间"></el-table-column>
      <el-table-column prop="username" label="用户账号"></el-table-column>
      <el-table-column prop="shop_name" label="买单小店"></el-table-column>
      <el-table-column  label="是否会员">
        <template slot-scope="scope">
          <p v-if="scope.row.is_vip === 0">否</p>
          <p v-if="scope.row.is_vip === 1">是</p>
        </template>
      </el-table-column>
      <el-table-column  label="买单金额">
        <template slot-scope="scope">
          ¥ {{scope.row.total_amount}}
        </template>
      </el-table-column>
      <el-table-column  label="满减优惠">
          <template slot-scope="scope">
         -¥ {{scope.row.price}}
        </template>
      </el-table-column>
      <el-table-column  label="会员折扣">
         <template slot-scope="scope">
          <p v-if="Number(scope.row.vip_discount_price) > 0">-¥ {{scope.row.vip_discount_price}}</p>
          <p v-else>-¥ {{scope.row.vip_day_discount_price}}</p>
        </template>
      </el-table-column>
      <el-table-column  label="实付金额">
         <template slot-scope="scope">
          ¥ {{scope.row.actual_amount}}
        </template>
      </el-table-column>
      <el-table-column  label="返红包金额" >
         <template slot-scope="scope">
          ¥ {{scope.row.rebate_money}}
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注"></el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        @current-change="pageChange"
        :current-page="form.page"
        :page-size="form.size"
        layout="total, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import {preferentialOrderList} from "@/api/shopdetail"
export default {
  data () {
    return {
      form: {
        username: '',
        shop_name:'',
        page: 1,
        size: 20
      },
      total:0,
      listLoading: false,
      tableData: [],
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    pageChange(page) {
      this.form.page = page;
      this.getList();
    },
    searchSaleOrder(){
      this.form.page = 1;
      this.getList();
    },
    // handleSizeChange(val) {
    //   this.form.size = val;
    //   this.pageChange(1);
    // },
    tc() {
      return "text-align:center; color:#333333; font-size:12px;";
    },
    tccolor() {
      return "text-align:center;background-color:#f5f5f5; font-size:14px;";
    },
    async getList () {
      // const form = this.form;
      this.listLoading = true;
      var url = 'username='+this.form.username+
                '&shop_name='+this.form.shop_name+
                '&page='+this.form.page+
                '&size='+this.form.size
      let res =  await preferentialOrderList(url)
      if(res.code === 10000){
         this.listLoading = false
         this.tableData = res.data.data
         this.total = res.data.total
      }else{
         this.listLoading = false
         this.$message.error(res.message);
         
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.shop {
  padding: 20px;
  .form{
    float: right;
  }
  .pagination{
    float: right;
    margin-top: 30px;
  }
}
</style>